package com.liziguo.lzgfp.system.codec;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageCodec;

import java.util.List;

/**
 * @Author: Liziguo
 * @Date: 2021/12/24 14:10
 */
public class JSONObjectCodec extends MessageToMessageCodec<String, JSONObject> {

    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, JSONObject jsonObject, List<Object> list) throws Exception {
        list.add(jsonObject.toJSONString());
    }

    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, String s, List<Object> list) throws Exception {
        list.add(JSON.parseObject(s));
    }
}
